home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig10_01.jar / Ch10 / Fig10_01 / Commis1.cpp < prev    next >
C/C++ Source or Header  |  1997-10-28  |  1KB  |  39 lines

  1. // Fig. 10.1: commis1.cpp
  2. // Member function definitions for class CommissionWorker
  3. #include <iostream.h>
  4. #include "commis1.h"
  5.  
  6. // Constructor for class CommissionWorker
  7. CommissionWorker::CommissionWorker( const char *first,
  8.         const char *last, double s, double c, int q )
  9.    : Employee( first, last )  // call base-class constructor
  10. {
  11.    setSalary( s );
  12.    setCommission( c );
  13.    setQuantity( q );
  14. }
  15.  
  16. // Set CommissionWorker's weekly base salary
  17. void CommissionWorker::setSalary( double s ) 
  18.    { salary = s > 0 ? s : 0; }
  19.  
  20. // Set CommissionWorker's commission
  21. void CommissionWorker::setCommission( double c )
  22.    { commission = c > 0 ? c : 0; }
  23.  
  24. // Set CommissionWorker's quantity sold
  25. void CommissionWorker::setQuantity( int q )
  26.    { quantity = q > 0 ? q : 0; }
  27.  
  28. // Determine CommissionWorker's earnings
  29. double CommissionWorker::earnings() const
  30.    { return salary + commission * quantity; }
  31.  
  32. // Print the CommissionWorker's name 
  33. void CommissionWorker::print() const
  34. {
  35.    cout << "\nCommission worker: ";
  36.    Employee::print();
  37. }
  38.  
  39.